﻿using B.S.DataBase.MyProject.ErrorCode;
using B.S.Traceability.Domain;
using B.S.Traceability.Infrastructure.Interface;
using B.S.Traceability.Read.API.Applicantion.Command.HealthCommand;
using MediatR;

namespace B.S.Traceability.Read.API.Applicantion.CommandHandler.HealthCommandHandler
{
    public class QueryHealthCommandHandler:IRequestHandler<QueryHealthCommand,APIResult<List<SU_Health>>>
    {
        private readonly IBaseRepository<SU_Health> healthRep;
        public QueryHealthCommandHandler(IBaseRepository<SU_Health> healthRep)
        {
            this.healthRep = healthRep;
        }
        public Task<APIResult<List<SU_Health>>> Handle(QueryHealthCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<SU_Health>> result = new APIResult<List<SU_Health>>();
            var list = healthRep.GetAll().Result.Where(x => x.ProductionCode == request.ProductionCode&&x.IsDel==false);
            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();
            result.data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
